﻿#include "VAOneXMLAdaptorAcousticsNCTResistiveTrimLayer.h"

#include "FITKAcousticsPhysics/FITKAcousticsNCTResistive.h"

namespace IO
{

    bool VAOneXMLAdaptorAcousticsNCTResistiveTrimLayer::adaptR()
    {
        return readNCTResistive();
    }

    bool VAOneXMLAdaptorAcousticsNCTResistiveTrimLayer::adaptW()
    {
        return writeNCTResistive();
    }

    bool VAOneXMLAdaptorAcousticsNCTResistiveTrimLayer::readNCTResistive()
    {
        if (!_node)// 判断节点是否存在
        {
            return false;
        }

        bool b = true;

        //转换类型
        Acoustics::FITKAcousticsNCTResistive* layerData = dynamic_cast<Acoustics::FITKAcousticsNCTResistive*>(_dataObj);

        if(!layerData)
        {
            return false;
        }

        double density = readDoubleAttribute(_node, "density", &b);

        if(b)
        {
             layerData->setDensity(density);
        }

        double thickness = readDoubleAttribute(_node, "thickness", &b);

        if(b)
        {
            layerData->setThickness(thickness);
        }

        double flowResistivity = readDoubleAttribute(_node, "flow_resistivity", &b);

        if(b)
        {
            layerData->setFlowResistivity(flowResistivity);
        }

        return true;
    }

    bool VAOneXMLAdaptorAcousticsNCTResistiveTrimLayer::writeNCTResistive()
    {
        if (!_node)// 判断节点是否存在
        {
            return false;
        }

        //转换类型
        Acoustics::FITKAcousticsNCTResistive* layerData = dynamic_cast<Acoustics::FITKAcousticsNCTResistive*>(_dataObj);

        if(!layerData)
        {
            return false;
        }

        //创建常规板节点
        rapidxml::xml_node<char>* node = createNodeElement(_node, "ResistiveTrimLayer");

        if(!node)
        {
            return false;
        }

        //写如属性值
        //写厚度
        writeAttribute(node, "thickness", layerData->getThickness());
        writeAttribute(node, "density", layerData->getDensity());
        writeAttribute(node, "flow_resistivity", layerData->getFlowResistivity());
        return true;
    }

}
